import { useEffect,useState } from 'react';
import { useFocusEffect } from '@react-navigation/native';
import { 
    StatusBar,
    Text, 
    View,
    Button
  } from 'react-native';

  export default function Home({navigation}) {
    const [num,setNum] = useState(0); //离开该页面再返回，不会销毁num的值
    
    useFocusEffect(()=>{  //切换页面，会反复执行的
        console.log('useFocusEffect')
    })

    useEffect(()=>{  //切换页面不会反复执行
        console.log('useEffect')
    })
    const goDetail = ()=>{
        navigation.navigate('detail',{userName:'张三'})
    }
    const addStateNum = () =>{
        setNum(num+1)
    }


    return(
        <View>
            <Button
                title='to detail'
                onPress={goDetail}
            />
            <Button
                title='Num +1'
                onPress={addStateNum}
            />
            <Text>{num}</Text>
            <StatusBar/>
        </View>
    )
  }